use std::{
    collections::HashMap,
    sync::{Arc, Mutex},
};

use datasource_connector::modeling_connector::SimpleMetaConnector;
use model_graph_common::transport::http::http_get;

use model_graph_types::{
    container::workflow::{
         ListOperatorStatement, MetaOperatorStatement,
        WorkflowBlockExecuteResult, WorkflowBlockExecuteResultBuilder,
        WorkflowBlockExecuteResultStatus,
    },
    modeling::{MetaConnector, Value},
};

use crate::workflow::context::WorkflowContext;

pub async fn execute(
    statement: &MetaOperatorStatement,
    context: Arc<Mutex<WorkflowContext>>,
) -> anyhow::Result<WorkflowBlockExecuteResult> {
    //

    let method = &statement.method;
    let identifier = &statement.identifier;

    if method == "get" {
        // 获取一个类的元数据
        let result = SimpleMetaConnector::default().get_class(identifier).await;
        match result {
            Ok(v) => {
                let mut outputs: HashMap<String, Value> = HashMap::new();

                outputs.insert(String::from("result"), v.try_into()?);

                Ok(WorkflowBlockExecuteResultBuilder::default()
                    .status(WorkflowBlockExecuteResultStatus::Succeeded)
                    .source_handle("source")
                    .result(outputs)
                    .build()?)
            }
            Err(err) => Ok(WorkflowBlockExecuteResult::succeed()),
        }
    } else {
        Ok(WorkflowBlockExecuteResult::succeed())
    }
}
